package com.groupfour.attendancemanagementsystem.service.impl;

import com.groupfour.attendancemanagementsystem.dao.ProjectGroupDao;

import com.groupfour.attendancemanagementsystem.entity.DO.ProjectGroupDO;
import com.groupfour.attendancemanagementsystem.entity.DO.ProjectGroupMembersDO;
import com.groupfour.attendancemanagementsystem.entity.DO.StudentDO;
import com.groupfour.attendancemanagementsystem.service.ProjectGroupService;
import com.groupfour.attendancemanagementsystem.utils.Result;
import io.swagger.models.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * serviceimpl层
 */
@Service
public class ProjectGroupImpl implements ProjectGroupService {
    private ProjectGroupDao projectGroupDao;

    @Autowired
    public ProjectGroupImpl(ProjectGroupDao projectGroupDao) {
        this.projectGroupDao = projectGroupDao;
    }

    @Override
    public int addProject(ProjectGroupDO projectGroupDO) {
        projectGroupDO.setGroupCode(projectGroupDO.getGroupName());
        Date date = new Date();
        projectGroupDO.setIsGraduation("0");
        projectGroupDO.setCreateTime(date);
        projectGroupDO.setDeleteStatus(0);
        return projectGroupDao.addProject(projectGroupDO);
    }

    @Override
    public int updataMember(String groupCode,String studentCode) {
        return projectGroupDao.updataMember(groupCode,studentCode);
    }

    @Override
    public int addMember(ProjectGroupMembersDO projectGroupMembersDO, HttpServletRequest request) {
        projectGroupMembersDO.setCreateTime(new Date());
        projectGroupMembersDO.setIsGroupLeader(0);
        return projectGroupDao.addMember(projectGroupMembersDO);
    }

    @Override
    public int updateProject(ProjectGroupDO projectGroupDO) {
        Date date = new Date();
        projectGroupDO.setUpdateTime(date);
        return projectGroupDao.updateProject(projectGroupDO);
    }

    @Override
    public int deleteProject(int groupId) {
        return projectGroupDao.deleteProject(groupId);
    }

    @Override
    public int deleteMember(int studentGroup) {
        return projectGroupDao.deleteMember(studentGroup);
    }

    @Override
    public List<ProjectGroupDO> selectProject(int isGraduation) {
        return projectGroupDao.selectProject(isGraduation);
    }

    @Override
    public List<StudentDO> selectMember(String groupName,String departmentName,String majorName,String gradeName,String classesName,String studentName,String studentCode,int studentId,int teacherId,int groupId) {
        Map map = new HashMap();
        map.put("groupName",gradeName);
        map.put("departmentName",departmentName);
        map.put("majorName",majorName);
        map.put("gradeName",gradeName);
        map.put("classesName",classesName);
        map.put("studentName",studentName);
        map.put("studentCode",studentCode);
        map.put("teacherId",teacherId);
        map.put("studentId",studentId);
        map.put("groupId",groupId);
        return projectGroupDao.selectMember(map);
    }

    @Override
    public int addFraction(String groupComment,double groupSyntnesisScore,int groupId) {
        return projectGroupDao.addFraction(groupComment,groupSyntnesisScore,groupId);
    }
    public ProjectGroupDO queryProject(String groupId,HttpServletRequest request){
        ProjectGroupDO projectGroupDO = projectGroupDao.queryProject(groupId);
        request.setAttribute("projectGroupDO",projectGroupDO);
        return projectGroupDO;
    }

    @Override
    public ProjectGroupDO queryByNameProject(String groupName) {
        return projectGroupDao.queryByNameProject(groupName);
    }

    @Override
    public int updateIsGroupleader(int isGroupLeader, String groupCode) {
        return projectGroupDao.updateIsGroupleader(isGroupLeader,groupCode);
    }

    @Override
    public List<ProjectGroupDO> selectProjectAll() {
        return projectGroupDao.selectProjectAll();
    }
}
